# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
#   cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
#   Mayor.create(name: 'Emanuel', city: cities.first)
DatabaseCleaner.clean_with :truncation

user = User.new
user.name = 'admin'
user.email = 'admin@qq.com'
user.password = '12345678'
user.password_confirmation = '12345678'
user.save!
role = Role.create(name: '管理员', abilities: ["首页", "客户管理", "配件管理", "来往单位管理", "基础数据管理", "工单管理", "服务管理", "财务管理", "统计分析", "人员管理", ""])
user_role_relation = UserRoleRelation.create(user_id: 1, role_id: 1)

role = Role.create(name: '接车员', abilities: ["首页", "工单管理", ""])
role = Role.create(name: '服务员', abilities: ["首页", "服务管理", ""])
role = Role.create(name: '财务员', abilities: ["首页", "财务管理", ""])
user = User.create(email: 'jc@qq.com', password: '12345678', name: '接车员')
user_role_relation = UserRoleRelation.create(user_id: 2, role_id: 2)
user = User.create(email: 'fw@qq.com', password: '12345678', name: '服务员')
user_role_relation = UserRoleRelation.create(user_id: 3, role_id: 3)
user = User.create(email: 'cw@qq.com', password: '12345678', name: '财务员')
user_role_relation = UserRoleRelation.create(user_id: 4, role_id: 4)

10.times do |n|
  Insurer.create(code: rand(100000).to_s.rjust(6, "0"), name: "保险公司" + n.to_s, phone: "123123123", fax: "321321321", email: "111@111.com")
end

CustomerLevel.create(name: '普通客户')
CustomerLevel.create(name: '会员')
Customer.create(customer_level_id: 1, name: '陈先生', phone: '13613613613', car_num: '粤S12345', car_mo: '宝马', car_colour: '红色', car_fnum: '123123', car_enum: '456456', insurer_id: 1)
Customer.create(customer_level_id: 2, name: '李先生', phone: '13713713713', car_num: '粤S99999', car_mo: '奔驰', car_colour: '白色', car_fnum: '666666', car_enum: '777777', insurer_id: 2)


10.times do |n|
  Supplier.create(code: rand(100000).to_s.rjust(6, "0"), name: "供应商" + n.to_s, phone: "123123123", fax: "321321321", email: "111@111.com", addr: "东莞市", tax_num: "abc")
end

Staff.create(name: 'A员工', phone: '123123123', sex: '男')
Staff.create(name: 'B员工', phone: '123123123', sex: '男')
Staff.create(name: 'C员工', phone: '123123123', sex: '男')

%w(
现金
刷卡
挂账
转账
微信
支付宝
).each do |w|
  PaymentMethod.create(name: w)
end

%w(
进口蜡水洗车
蜡水洗车七座或以上小车
内外精细洗车
精细洗车七座或以上小车
座套清洗
座套拆装（不包清洗）
洗座套（不包装）
清洗标签（前档）
消毒（不含洗车）
全车室内环保清洁杀菌护理
空调清洗
真皮护理
金属还原护理
前挡玻璃镀膜
全车玻璃镀膜
发动机仓除污护理
发动机深层清洁护理
漆面磨泥自带蜡（不含洗车）
镀膜护理
漆面起迹水晶蜡
漆面起迹密封
漆面研磨还原（浅色车）
漆面研磨还原（黑色车及大车）
漆面保护（含洗车）
单幅漆面研磨还原（不含洗车）
极品镀晶
).each do |w|
  BeautyItem.create(name: w, amount: 50, working_hour: 2)
end


PartStyle.create(name: '车镜', parts_attributes: [{name: '后视镜', code: rand(100000).to_s.rjust(6, "0"), purchase_price: 10, sales_price: 15, unit: "个"},
												  {name: '遮阳板', code: rand(100000).to_s.rjust(6, "0"), purchase_price: 10, sales_price: 15, unit: "个"}										                                                                   
											      ])

PartStyle.create(name: '车门&车窗', parts_attributes: [{name: '玻璃升降器', code: rand(100000).to_s.rjust(6, "0"), purchase_price: 10, sales_price: 15, unit: "个"},
												      {name: '车窗', code: rand(100000).to_s.rjust(6, "0"), purchase_price: 10, sales_price: 15, unit: "个"},
												      {name: '车门', code: rand(100000).to_s.rjust(6, "0"), purchase_price: 10, sales_price: 15, unit: "个"}	                                                                   
      	                                              ])

PartStyle.create(name: '车身&车顶', parts_attributes: [{name: '保险杠', code: rand(100000).to_s.rjust(6, "0"), purchase_price: 10, sales_price: 15, unit: "个"},
												      {name: '车标', code: rand(100000).to_s.rjust(6, "0"), purchase_price: 10, sales_price: 15, unit: "个"},
												      {name: '挡泥板', code: rand(100000).to_s.rjust(6, "0"), purchase_price: 10, sales_price: 15, unit: "个"},	                                                                   
												      {name: '驾驶室', code: rand(100000).to_s.rjust(6, "0"), purchase_price: 10, sales_price: 15, unit: "个"},
												      {name: '天窗', code: rand(100000).to_s.rjust(6, "0"), purchase_price: 10, sales_price: 15, unit: "个"},
												      {name: '叶子板', code: rand(100000).to_s.rjust(6, "0"), purchase_price: 10, sales_price: 15, unit: "个"}
	                                                  ])


MaintainStyle.create(name: '发动机维修作业', maintain_items_attributes: [{name: '更换机油及滤清器', amount: 50, working_hour: 2},
	                                                                    {name: '更换燃油滤清器', amount: 50, working_hour: 2},
	                                                                    {name: '清洗或更换空气滤清器', amount: 50, working_hour: 2},
	                                                                    {name: '更换燃油泵', amount: 50, working_hour: 2},
	                                                                    {name: '检查防冻液液面、冻结温度、添加防冻液或更换防冻液', amount: 50, working_hour: 2},
	                                                                    {name: '更换正时皮带、调整或更换正时带轮', amount: 50, working_hour: 2},
	                                                                    {name: '检查调整或更换发电机、转向助力、风扇、空调压缩机皮带', amount: 50, working_hour: 2},
	                                                                    {name: '检查清洗或更换喷油器', amount: 50, working_hour: 2},
	                                                                    {name: '清洗、更换节气门', amount: 50, working_hour: 2},
	                                                                    {name: '更换节气门拉线', amount: 50, working_hour: 2},
	                                                                    {name: '更换怠速控制阀', amount: 50, working_hour: 2},
	                                                                    {name: '检查、清洗或更换火花塞', amount: 50, working_hour: 2},
	                                                                    {name: '检测、更换点火高压线', amount: 50, working_hour: 2}
	                                                                    ])

MaintainStyle.create(name: '底盘维修作业', maintain_items_attributes: [{name: '检查、调整离合器踏板', amount: 50, working_hour: 2},
		                                                                {name: '检查离合器液面或添加更换离合器液', amount: 50, working_hour: 2},
		                                                                {name: '更换离合器总泵、分泵 ', amount: 50, working_hour: 2},
		                                                                {name: '更换离合器拉线', amount: 50, working_hour: 2},
		                                                                {name: '检查离合器管路渗漏情况或更换离合器软管', amount: 50, working_hour: 2},
		                                                                {name: '检查、调整驻车制动器', amount: 50, working_hour: 2},
		                                                                {name: '检查、调整制动踏板位置', amount: 50, working_hour: 2},
		                                                                {name: '更换驻车制动拉线', amount: 50, working_hour: 2},
		                                                                {name: '检查制动液面或添加、更换制动液', amount: 50, working_hour: 2},
		                                                                {name: '更换制动助力器', amount: 50, working_hour: 2},
		                                                                {name: '更换制动总泵、分泵', amount: 50, working_hour: 2},
		                                                                {name: '检查制动管路渗漏情况或更换制动软管', amount: 50, working_hour: 2},
		                                                                {name: '检查变速器油面高度、油质或添加、更换变速器油', amount: 50, working_hour: 2}
		                                                                ])


5.times do |n|
  Package.create(name: "套餐" + n.to_s)
end

Warehouse.create(name: "仓库1")
WarehouseSlot.create(warehouse_id: 1, name: "仓位1")